home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / util / libs / ttengine.lha / ttengine-4.1 / Examples / SpeedTest / speed.c < prev    next >
C/C++ Source or Header  |  2002-09-29  |  8KB  |  199 lines

  1. /* test ttrender */
  2.  
  3. #define __NOLIBBASE__
  4.  
  5. #include <proto/dos.h>
  6. #include <proto/exec.h>
  7. #include <proto/intuition.h>
  8. #include <proto/graphics.h>
  9. #include <proto/ttengine.h>
  10. #include <proto/asl.h>
  11. #include <proto/timer.h>
  12.  
  13. #include <libraries/ttengine.h>
  14.  
  15. extern struct Library *SysBase, *DOSBase;
  16.  
  17. struct Library *TTEngineBase, *IntuitionBase, *GfxBase, *AslBase, *TimerBase,
  18.                *MathIeeeSingBasBase;
  19.  
  20. LONG EClock;
  21.  
  22. /*----------------------------------------------------------------------------------------------------*/
  23.  
  24. static STRPTR get_font_name(struct Library *AslBase)
  25.   {
  26.     struct FileRequester *freq;
  27.     STRPTR name = NULL;
  28.  
  29.     if (freq = AllocAslRequestTags(ASL_FileRequest, TAG_END))
  30.       {
  31.         if (AslRequestTags(freq,
  32.           ASLFR_TitleText, (ULONG)"Select TrueType font",
  33.           ASLFR_InitialDrawer, (ULONG)"FONTS:",
  34.           ASLFR_DoPatterns, TRUE,
  35.           ASLFR_InitialPattern, (ULONG)"#?.ttf",
  36.           ASLFR_RejectIcons, TRUE,
  37.           TAG_END))
  38.           {
  39.             ULONG namelen = strlen(freq->fr_File) + strlen(freq->fr_Drawer) + 4;
  40.  
  41.             if (name = AllocVec(namelen + 1, MEMF_ANY | MEMF_CLEAR))
  42.               {
  43.                 strncpy(name, freq->fr_Drawer, namelen);
  44.                 AddPart(name, freq->fr_File, namelen);
  45.               }
  46.           }
  47.         FreeAslRequest(freq);
  48.       }
  49.     return name;
  50.   }
  51.  
  52. /*----------------------------------------------------------------------------------------------------*/
  53.  
  54. static VOID free_font_name(STRPTR name)
  55.   {
  56.     if (name) FreeVec(name);
  57.   }
  58.  
  59.  
  60. void test_loop(struct RastPort *rp)
  61.   {
  62.     WORD a, b;
  63.     struct EClockVal start, stop;
  64.     LONG speed;
  65.  
  66.     ReadEClock(&start);
  67.     for (a = 10; a < 410; a += 10)
  68.       {
  69.         SetAPen(rp, a >> 3);
  70.         SetBPen(rp, ~(a >> 3));
  71.         for (b = 40; b < 440; b += 16)
  72.           {
  73.             Move(rp, a, b);
  74.             TT_Text(rp, "speed test", 10);
  75.           }
  76.       }
  77.     ReadEClock(&stop);
  78.     if (stop.ev_lo < start.ev_lo) stop.ev_lo = !(start.ev_lo - stop.ev_lo);
  79.     else stop.ev_lo -= start.ev_lo;
  80.     speed = IEEESPFix(IEEESPDiv(IEEESPMul(IEEESPFlt(10000), IEEESPFlt(EClock)), IEEESPFlt(stop.ev_lo)));
  81.     Printf("%ld glyphs per second.\n", speed);
  82.   }
  83.  
  84. /*----------------------------------------------------------------------------------------------------*/
  85.  
  86. int Main (void)
  87.   {
  88.     struct Window *win;
  89.     STRPTR fontname;
  90.     APTR font;
  91.  
  92.     if (GfxBase = OpenLibrary("graphics.library", 39))
  93.       {
  94.         if (IntuitionBase = OpenLibrary("intuition.library", 39))
  95.           {
  96.             if (AslBase = OpenLibrary("asl.library", 38))
  97.               {
  98.                 if (fontname = get_font_name(AslBase))
  99.                   {
  100.                     if (TTEngineBase = OpenLibrary("ttengine.library", 0))
  101.                       {
  102.                         if (win = OpenWindowTags(NULL,
  103.                           WA_Top, 25,
  104.                           WA_Left, 0,
  105.                           WA_Width, 640,
  106.                           WA_Height, 480,
  107.                           WA_CloseGadget, TRUE,
  108.                           WA_DragBar, TRUE,
  109.                           WA_DepthGadget, TRUE,
  110.                           WA_IDCMP, IDCMP_CLOSEWINDOW,
  111.                           WA_Title, (ULONG)"ttengine library speed test",
  112.                           TAG_END))
  113.                           {
  114.                             ULONG sigmask, signals;
  115.                             BOOL running = TRUE;
  116.                             struct RastPort *rp = win->RPort;
  117.  
  118.                             if (font = TT_OpenFont(
  119.                               TT_FontFile, (ULONG)fontname,
  120.                               TT_FontSize, 16,
  121.                             TAG_END))
  122.                               {
  123.                                 struct timerequest req;
  124.                                 struct EClockVal ev;
  125.  
  126.                                 if (MathIeeeSingBasBase = OpenLibrary("mathieeesingbas.library", 37))
  127.                                   {
  128.                                     if (OpenDevice ("timer.device", UNIT_ECLOCK, (struct IORequest*)&req, 0) == 0)
  129.                                       {
  130.                                         TimerBase = (struct Library*)req.tr_node.io_Device;
  131.                                         EClock = ReadEClock(&ev);
  132.  
  133.                                         Printf("E clock will be used for measurements, frequency is %ld Hz.\n", EClock);
  134.  
  135.                                         TT_SetFont(rp, font);
  136.                                         TT_SetAttrs(rp,
  137.                                           TT_Window, (ULONG)win,
  138.                                           TT_Antialias, TT_Antialias_Off,
  139.                                         TAG_END);
  140.  
  141.                                         SetDrMd(rp, JAM1);
  142.                                         Printf("Antialias: OFF, mode: JAM1\n");
  143.                                         test_loop(rp);
  144.                                         EraseRect(rp, win->BorderLeft, win->BorderTop, win->Width - win->BorderRight, win->Height - win->BorderBottom);
  145.  
  146.                                         TT_SetAttrs(rp, TT_Antialias, TT_Antialias_On, TAG_END);
  147.                                         Printf("Antialias: ON, mode: JAM1\n");
  148.                                         test_loop(rp);
  149.                                         EraseRect(rp, win->BorderLeft, win->BorderTop, win->Width - win->BorderRight, win->Height - win->BorderBottom);
  150.  
  151.                                         SetDrMd(rp, JAM2);
  152.                                         Printf("Antialias: ON, mode: JAM2\n");
  153.                                         test_loop(rp);
  154.                                         EraseRect(rp, win->BorderLeft, win->BorderTop, win->Width - win->BorderRight, win->Height - win->BorderBottom);
  155.  
  156.                                         TT_SetAttrs(rp, TT_Antialias, TT_Antialias_Off, TAG_END);
  157.                                         Printf("Antialias: OFF, mode: JAM2\n");
  158.                                         test_loop(rp);
  159.                                         EraseRect(rp, win->BorderLeft, win->BorderTop, win->Width - win->BorderRight, win->Height - win->BorderBottom);
  160.  
  161.                                         CloseDevice((struct IORequest*)&req);
  162.                                       }
  163.                                     CloseLibrary(MathIeeeSingBasBase);
  164.                                   }
  165.                                 TT_CloseFont(font);
  166.                               }
  167.                             else PutStr("Font open failed.\n");
  168.  
  169.                             sigmask = SIGBREAKF_CTRL_C | (1 << win->UserPort->mp_SigBit);
  170.                             while (running)
  171.                               {
  172.                                 signals = Wait(sigmask);
  173.                                 if (signals & SIGBREAKF_CTRL_C) running = FALSE;
  174.                                 if (signals & (1 << win->UserPort->mp_SigBit))
  175.                                   {
  176.                                     struct IntuiMessage *imsg;
  177.  
  178.                                     while (imsg = (struct IntuiMessage*)GetMsg(win->UserPort))
  179.                                       {
  180.                                         if (imsg->Class == IDCMP_CLOSEWINDOW) running = FALSE;
  181.                                         ReplyMsg((struct Message*)imsg);
  182.                                       }
  183.                                   }
  184.                               }
  185.                             CloseWindow(win);
  186.                           }
  187.                         CloseLibrary(TTEngineBase);
  188.                       }
  189.                     free_font_name(fontname);
  190.                   }
  191.                 CloseLibrary(AslBase);
  192.               }
  193.             CloseLibrary(IntuitionBase);
  194.           }
  195.         CloseLibrary(GfxBase);
  196.       }
  197.     return 0;
  198.   }
  199.